package com.hc.acoustics.ui.activity

import android.content.Intent
import android.os.Bundle
import com.hc.acoustics.R
import com.hc.acoustics.base.BaseActivity
import com.hc.acoustics.util.FormulaUtil
import com.yc.yclibrary.base.YcAppCompatActivity
import kotlinx.android.synthetic.main.formula_button.*
import kotlinx.android.synthetic.main.type3_formula4_location_activity.*
import kotlinx.android.synthetic.main.type3_formula5_location_activity.*
import kotlinx.android.synthetic.main.type3_formula6_location_activity.*
import kotlinx.android.synthetic.main.type3_formula7_location_activity.*
import java.lang.NumberFormatException

/**
 *  电子学 - 两个信号相同，幅度相同，相位不同叠加
 */
class Type3Formula7Activity : BaseActivity() {

    companion object {
        private const val KEY_TITLE = "key_title"
        @JvmStatic
        fun newInstance(activity: YcAppCompatActivity, title: String) {
            val intent = Intent(activity, Type3Formula7Activity::class.java)
            intent.putExtra(KEY_TITLE, title)
            activity.startActivity(intent)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.type3_formula7_location_activity
    }

    override fun initView(savedInstanceState: Bundle?) {
        setActionBar(intent.getStringExtra(KEY_TITLE))
        formulaResetBtn.setOnClickListener {
            formula3_7_a_TEV.reset()
            formula3_7_b_TEV.reset()
            formula3_7_dB_TEV.reset()
        }
        formulaOkBtn.setOnClickListener {
            try {
                val result = FormulaUtil.formula3_7(
                    formula3_7_a_TEV.getDouble(),
                    formula3_7_b_TEV.getDouble()
                )
                formula3_7_dB_TEV.setText(result)
            } catch (e: NumberFormatException) {
                formula3_7_dB_TEV.setText("Infinity")
            }
        }
    }
}